package com.itboye.sunsun.test;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.android.volley.Request;
import com.android.volley.Request.Method;
import com.android.volley.Response.ErrorListener;
import com.android.volley.VolleyError;
import com.itboye.sunsun.beans.PersonDataBean;
import com.itboye.sunsun.constants.NetPublicConstant;
import com.itboye.sunsun.network.HttpRequest;
import com.itboye.sunsun.test.bean.BikeBean;
import com.itboye.sunsun.test.bean.WeatherBean;
import com.itboye.sunsun.utils.DebugLog;
import com.itboye.sunsun.utils.ParamDeal;
import com.itboye.sunsun.utils.TimesUtils;
import com.itboye.sunsun.volley.MyJsonRequest;
import com.itboye.sunsun.volley.XErrorListener;
import com.itboye.sunsun.volley.XJsonRequest;
import com.itboye.sunsun.volley.XRequestListener;
import com.nostra13.universalimageloader.utils.StorageUtils;

import android.content.Context;

public class VolleyExample {

	
	public static void main(){
		
//		HttpRequest.getDefaultRequestQueue().add(  bike()  );
		
		//HttpRequest.getDefaultRequestQueue().add(  weather()  );
	   login();
		
	}
	
	
	
	
	
	 


	public static void login()
	{
		MyJsonRequest<PersonDataBean>request= new MyJsonRequest.Builder<PersonDataBean>()
		 .apiVer("100")
		 .typeKey("BY_User_login")
		 .requestListener(new XRequestListener<PersonDataBean>() {

			@Override
			public void onResponse(PersonDataBean response) {
				// TODO Auto-generated method stub
				DebugLog.v("result", response.toString());
			}
		})
		 .errorListener(new XErrorListener() {

			@Override
			public void onErrorResponse(Exception exception, int code, String msg) {
				// TODO Auto-generated method stub
				DebugLog.v("volleyerr","登录..."+exception);
			}

//			@Override
//			public void onErrorResponse(VolleyError error) {
//				// TODO Auto-generated method stub
//				DebugLog.v("volleyerr","登录..."+ error.toString());
//			}
		})
		.build();
		HttpRequest.getDefaultRequestQueue().add(request);
//		
		
//		String url="http://sunsun.itboye.com/api.php";
//		String time = TimesUtils.getStamp();
//		ParamDeal operate = new ParamDeal();
//		Map<String,String> map=new HashMap<>();
//		map.put("username", "12345678910");
//		map.put("password", "123456");
//		String data = operate.dataEncrypt(map);
//		String sign = operate.getMD5Sign(time, "BY_User_login", data,
//				NetPublicConstant.Client_Id_Value,
//				time);
//		
//		
//		XJsonRequest<PersonDataBean>request2=new XJsonRequest<>(url, new XRequestListener<PersonDataBean>() {
//
//			@Override
//			public void onResponse(PersonDataBean response) {
//				DebugLog.v("result", response.toString());
//			}
//		}, new ErrorListener() {
//
//			@Override
//			public void onErrorResponse(VolleyError error) {
//				DebugLog.v("volleyerr","登录..."+ error.toString());
//			}
//		})
//		.addParam(NetPublicConstant.Grant_Type_Key,NetPublicConstant.Grant_Type_Value)
//		.addParam(NetPublicConstant.Client_Id_Key,NetPublicConstant.Client_Id_Value)
//		.addParam(NetPublicConstant.Client_Secret_Key,NetPublicConstant.Client_Secret_Value)
//
//		// 公共参数
//		.addParam(NetPublicConstant.Time_Key,time)
//		.addParam(NetPublicConstant.Alg_Key,NetPublicConstant.Alg_Value)
//		
//		.addParam(NetPublicConstant.Notify_Id_Key,time)
//    	.addParam(NetPublicConstant.Access_Token_Key,NetPublicConstant.Client_Id_Value)
//    	
//    	// 请求数据
//    	
//		.addParam(NetPublicConstant.Type_Key, "BY_User_login")
//		.addParam(NetPublicConstant.API_Ver_Key,"100")
//		
//		.addParam(NetPublicConstant.Data_Key, data)
//		.addParam(NetPublicConstant.Sign_Key, sign)
//		;
//		
//		
//		
//		HttpRequest.getDefaultRequestQueue().add(request2);
	}
	
	
	private static Request<List<BikeBean>> bike() {

		String url = "http://hztrip.org/api/bike/round?lon=120.371964&lat=30.322133";

		XJsonRequest<List<BikeBean>> request = new XJsonRequest<List<BikeBean>>(  url, new XRequestListener<List<BikeBean>>() {

			@Override
			public void onResponse(List<BikeBean> response) {
				DebugLog.v("result", response.toString());
			}
		}, new XErrorListener() {

//			@Override
//			public void onErrorResponse(VolleyError error) {
//				DebugLog.v("volleyerr", "自行车.."+error.toString());
//			}

			@Override
			public void onErrorResponse(Exception exception, int code, String msg) {
				// TODO Auto-generated method stub
				
			}
		})  .setMethod(Method.GET) ;

		return request;

	}

	/**
	 * 获取  百度 api  store 天气信息
	 * @return
	 */
	private static Request<WeatherBean> weather() {
		String httpUrl = "http://apis.baidu.com/apistore/weatherservice/citylist";
		String httpArg = "cityname=%E6%9C%9D%E9%98%B3";
		String url = httpUrl + "?" + httpArg;
		XJsonRequest<WeatherBean> request = new XJsonRequest<WeatherBean>( Method.GET,url, new XRequestListener<WeatherBean>() {

			@Override
			public void onResponse(WeatherBean arg0) {
				DebugLog.v("result", arg0.toString());
			}
		}, new XErrorListener() {

//			@Override
//			public void onErrorResponse(VolleyError arg0) {
//				DebugLog.v("volleyerr", "天气。。"+arg0.toString());
//
//			}

			@Override
			public void onErrorResponse(Exception exception, int code, String msg) {
				// TODO Auto-generated method stub
				
			}
		}).addHeader("apikey", "0ec4ef9237be00e62fcda68c1417a28e");
				 

		return request;
	}

}
